package com.heima;

public class TestAnimal {
    public static void main(String[] args) {
        Animal[] animals = new Animal[5];
        animals[0] = new Animal("1猴子", 2, 20.0);
        animals[1] = new Animal("2猴子", 3, 30.0);
        animals[2] = new Animal("3猴子", 4, 40.0);
        animals[3] = new Animal("4猴子", 5, 50.0);
        animals[4] = new Animal("5猴子", 6, 60.0);
        int maxAge = animals[0].getAge();
        int minAge = animals[0].getAge();
        int indexMax = 0;
        int indexMin = 0;
        for (int i = 0; i < animals.length; i++) {
            if (maxAge < animals[i].getAge()) {
                maxAge = animals[i].getAge();
                indexMax = i;
            }
            if (minAge > animals[i].getAge()) {
                minAge = animals[i].getAge();
                indexMin = i;
            }
        }
        System.out.print(animals[indexMax].getType());
        animals[indexMax].eat();
        System.out.print(animals[indexMin].getType());
        animals[indexMin].eat();
    }
}
